<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/3/23 0023
 * Time: 11:38
 */

namespace app\admin\model;


use think\facade\Cache;
use think\facade\Db;
use think\Model;

class Gcategory extends  Model
{
    protected $pk='cate_id';
   public static  function getCateList($paramNew){
       $list=Gcategory::
           where("parent_id","=",$paramNew['parent_id'])
           ->order("sort_order")
           ->select();
       $list=$list->toArray();
       return $list;

   }
   public static function getParentId(){
       if (Cache::has("parentId")){
           $parentId=Cache::get("parentId");
       }else{
           $parentId=Gcategory::column("parent_id");
           Cache::set('parentId',$parentId,10);
       }


       return $parentId;
   }
    public static function goodsCateList(){
        $cate=Gcategory::select();

        return $cate;

    }

    public static function cateAdd($data)
    {
        $cateAdd=new Gcategory();
        try{
            $res=$cateAdd->save($data);
            $msg='成功';
        }catch (\Exception $e){
            $res=false;
            $msg=$e->getMessage();
        }
        return[$res,$msg];
    }

    public static function editCateList($data)
    {
        try{
          $res=Gcategory::update($data);
          $msg='成功';
        }catch (\Exception $e){
            $res=false;
            $msg=$e->getMessage();
        }
        return[$res,$msg];
    }



}